package com.tsf.hbase.jpa;

import java.io.Serializable;

/**
 * hbase分页对象
 *
 * @author taoningbo
 * @since 1.0, Created as 2018/11/26
 */
public final class Page implements Serializable {

    private static final long serialVersionUID = -370765201122077733L;

    /**
     * 默认最少分页大小：20条
     */
    public static final int DEFAULT_MIN_PAGE_SIZE = 20;

    /**
     * 默认最多分页大小：1000条
     */
    public static final int DEFAULT_MAX_PAGE_SIZE = 1000;

    /**
     * 下一批数据结果的第一条主键，即行的唯一索引值，为bytes
     * 的{@link org.apache.hadoop.hbase.util.Base64#encodeBytes(byte[])}值
     */
    private String firstRowKey;

    /**
     * 每一批数据的最大大小，默认值为{@link #DEFAULT_MIN_PAGE_SIZE}
     */
    private Integer pageSize;

    public Page() {
        this.setPageSize(DEFAULT_MIN_PAGE_SIZE);
    }

    public Page(Integer pageSize) {
        this.setPageSize(pageSize);
    }

    public Page(String firstRowKey, Integer pageSize) {
        this.firstRowKey = firstRowKey;
        this.setPageSize(pageSize);
    }

    public String getFirstRowKey() {
        return firstRowKey;
    }

    public void setFirstRowKey(String firstRowKey) {
        this.firstRowKey = firstRowKey;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if (pageSize < DEFAULT_MIN_PAGE_SIZE) {
            pageSize = Math.max(pageSize, DEFAULT_MIN_PAGE_SIZE);
        }
        if (pageSize > DEFAULT_MAX_PAGE_SIZE) {
            pageSize = Math.min(pageSize, DEFAULT_MAX_PAGE_SIZE);
        }
        this.pageSize = pageSize;
    }
}
